package com.epam.rentcar.controller.actions;

import java.sql.SQLException;

import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.epam.rentcar.model.CarRent;

public class ApproveRequestAction implements Action {

	private static Logger log = Logger.getLogger(ApproveRequestAction.class);

	@Override
	public String perform(HttpServletRequest request,
			HttpServletResponse response) throws ServletException {

		HttpSession session = request.getSession();

		CarRent carRentAppModel = (CarRent) session.getAttribute("carRentAppModel");

		int id = Integer.parseInt(request.getParameter("id"));

		try {
			carRentAppModel.approveRequest(id);
			carRentAppModel.setPaymentPurpose(id, "payment for rent");
		} catch (SQLException | NamingException e) {
			log.error(e);
			throw new ServletException(e);
		}
		return "/adminPage.jsp"; 
		
	}

}
